package com.share.user.api.factory;

import cn.hutool.system.UserInfo;
import com.share.common.core.domain.R;
import com.share.user.api.RemoteUserInfoService;
import com.share.user.api.model.LoginUserInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @author zt181
 * @date 2025/7/1
 */
@Component
public class RemoteUserInfoFallbackFactory implements FallbackFactory<RemoteUserInfoService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteUserInfoFallbackFactory.class);


    @Override
    public RemoteUserInfoService create(Throwable throwable) {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteUserInfoService()
        {
            @Override
            public R<LoginUserInfo> getUserInfoByCode(String code, String source) {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<LoginUserInfo> getUserInfo(Long userId, String inner) {
                return R.fail("获取用户信息失败:" + throwable.getMessage());
            }
        };
    }
}
